import * as sdk from './fetch';

/**
 *
 * 我的道具(不分页)
 *
 */
async function getMyProp(params): Promise<any> {
  let result = await sdk.get('mybackpack/list', params);
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 *
 * 我的道具 （分页）
 *
 */
async function getMyPropByPage(params): Promise<any> {
  let result = await sdk.get('mybackpack/page', params);
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 *
 * 使用道具
 *
 */
async function useProp(params): Promise<any> {
  let result = {
    context: '',
    code: '',
    message: '',
  };
  try {
    result = await sdk.post<any>(`mybackpack/usedProp`, {
      ...params,
    });
  } catch (e) {
    result = e;
  }

  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

export default {
  getMyProp,
  useProp,
  getMyPropByPage,
};
